//
//  JwHomeController.m
//  JwPack
//
//  Created by 陈警卫 on 2022/8/31.
//

#import "JwHomeController.h"
#import "UIColor+JwPack.h"

#import "JwHudController.h"
#import "JwHoldViewController.h"
#import "JwHoldImageController.h"
#import "JwWebJSController.h"
#import "JwCarouselController.h"
#import "JwExServiceController.h"
#import "FBtListController.h"

@interface JwHomeController ()<UITableViewDelegate, UITableViewDataSource>

@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) NSMutableArray *datas;

@end

@implementation JwHomeController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self setupView];
    [self setupData];
}

- (void)setupData {
    
    self.datas = @[@{@"name": @"主题",    @"vc": @""},
                   @{@"name": @"FBt",    @"vc": @"FBtListController"},
                   @{@"name": @"提示",    @"vc": @"JwHudController"},
                   @{@"name": @"页面站位", @"vc": @"JwHoldViewController"},
                   @{@"name": @"图片站位", @"vc": @"JwHoldImageController"},
                   @{@"name": @"WebJS",   @"vc": @"JwWebJSController"},
                   @{@"name": @"滚播",    @"vc": @"JwCarouselController"},
                   @{@"name": @"Http",   @"vc": @"JwExServiceController"},
    ].mutableCopy;
    
    [self.tableView reloadData];
}

- (void)setupView {
    self.tableView = [[UITableView alloc] initWithFrame:(CGRectZero) style:(UITableViewStylePlain)];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.backgroundColor = [UIColor clearColor];
    [self.view addSubview:self.tableView];
    [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.offset(0);
        make.top.offset(kJwScrNavBatBarHeight);
        make.bottom.offset(0);
    }];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.datas.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *identifier = @"UITableViewCell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:(UITableViewCellStyleDefault) reuseIdentifier:identifier];
    }
    
    cell.backgroundColor = [UIColor clearColor];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    NSDictionary *param = self.datas[indexPath.row];
    NSString *name = param[@"name"];
    cell.textLabel.text = name;
    cell.textLabel.jw_textColorKey = [UIColor jw_title].key;
    
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 50;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
    NSDictionary *param = self.datas[indexPath.row];
    NSString *name = param[@"name"];
    
    if ([name isEqualToString:@"主题"]) {
        [self themeAction];
    } else {
        [self pushAction:param];
    }
}

- (void)themeAction {
    if (kJwSkiner.currentSkinIndex == 0) {
        [kJwSkiner setupCurrentSkinIndex:1];
    } else {
        [kJwSkiner setupCurrentSkinIndex:0];
    }
}

- (void)pushAction:(NSDictionary *)param {
    NSString *vcs = param[@"vc"];
    Class vsClass = NSClassFromString(vcs);
    UIViewController *vc = [[vsClass alloc] init];
    [self.navigationController pushViewController:vc animated:YES];
}


@end
